package com.future.hedongjun.mine.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;

import com.future.baselib.activity.BaseActivity;
import com.future.baselib.entity.BaseResponse;
import com.future.baselib.entity.DefaultResponse;
import com.future.baselib.http.HttpRequest;
import com.future.hedongjun.R;
import com.future.hedongjun.common.MyApp;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class EditPwdActivity extends BaseActivity {

    @BindView(R.id.et_pwd)
    EditText etPwd;
    @BindView(R.id.et_pwd_again)
    EditText etPwdAgain;
    @BindView(R.id.btn_ok)
    Button btnOk;
    private String code;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_pwd);
        ButterKnife.bind(this);
        setTitle("修改密码");
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        super.getBundleExtras(extras);
        code = extras.getString("code");
    }

    @OnClick(R.id.btn_ok)
    public void onViewClicked() {
        String pwd = etPwd.getText().toString().trim();
        if (TextUtils.isEmpty(pwd)) {
            toast("密码不能为空");
            return;
        }
        String pwdAgain = etPwdAgain.getText().toString().trim();
        if (TextUtils.isEmpty(pwdAgain)) {
            toast("确认密码不能为空");
            return;
        }
        if (!TextUtils.equals(pwd, pwdAgain)) {
            toast("两次密码输入不一致");
            return;
        }
        new HttpRequest<DefaultResponse>()
                .with(this)
                .setPath("/api/User/resetpwd")
                .addParam("mobile", MyApp.getInstance().getUserInfo().getMobile())
                .addParam("token", MyApp.getInstance().getUserInfo().getToken())
                .addParam("captcha", code)
                .addParam("newpassword", pwd)
                .addSuccessListener(new HttpRequest.OnNetworkSuccess() {
                    @Override
                    public void onSuccess(BaseResponse response) {
                        startActivity(SettingActivity.class);
                    }
                }).start(new DefaultResponse());

    }
}
